﻿namespace WMS.Common
{
    /// <summary>
    /// 封装返回结果
    /// </summary>
    [Serializable]
    public class ApiResult
    {
        public ApiResult(string reason)
        {
            isSuc = false;
            code = StatusCodeEnum.Fail;
            msg = reason;
        }

        /// <summary>
        /// 是否成功
        /// </summary>
        public bool isSuc { get; set; }

        /// <summary>
        /// 接口请求结果的状态码
        /// </summary>
        public StatusCodeEnum code { get; set; }
        /// <summary>
        /// 返回的信息
        /// </summary>
        public string msg { get; set; } = string.Empty;

        /// <summary>
        /// 成功的方法
        /// </summary>
        public void Success()
        {
            isSuc= true;
            code = StatusCodeEnum.Ok;
            msg = "操作成功";
        }
    }

    public class ApiResult<T> : ApiResult
    {
        public ApiResult(string reason) : base(reason)
        {

        }

        /// <summary>
        /// 数据
        /// </summary>
        public T? data { get; set; }

        /// <summary>
        /// 带参数的成功返回
        /// </summary>
        /// <param name="result"></param>
        public void Success(T result)
        {
            isSuc = true;
            code = StatusCodeEnum.Ok;
            msg = "操作成功";
            data = result;
        }

        
    }
}
